package com.yusheng.tr.multi.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.yusheng.domain.R;
import com.yusheng.tr.common.core.model.dto.multi.ModelMngDto;
import com.yusheng.tr.common.log.annotation.Log;
import com.yusheng.tr.common.log.enums.BusinessType;
import com.yusheng.tr.common.core.entity.multi.ModelMngEntity;
import com.yusheng.tr.multi.service.IModelMngService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 模型管理表
 * </p>
 *
 * @author author
 * @since 2023-10-02
 */
@RestController
@RequestMapping("/model-mng")
@Tag(name = "模型管理表功能")
public class ModelMngController {

    @Autowired
    private IModelMngService modelMngService;

    @Log(title = "新增模型管理，名称不能重复", businessType = BusinessType.INSERT)
    @Operation(summary = "新增或者修改模型管理",description = "新增或者修改模型管理")
    @Parameter(name = "dto",description = "模型实体参数")
    @PostMapping("/add/or/update")
    public R<?> insertModel(@RequestBody ModelMngDto dto){
        modelMngService.addOrUpdate(dto);
        return R.ok();
    }


    @GetMapping("/page/list")
    @Operation(summary = "模型管理列表",description = "模型管理列表")
    @Parameters({
            @Parameter(name = "name",description = "模型名称"),
            @Parameter(name = "pageNum",description = "当前页数"),
            @Parameter(name = "pageSize",description = "当前页数的记录数")
    })
    public R<PageInfo<ModelMngEntity>> pageInfo(String name,Integer pageNum,Integer pageSize){
        return R.ok(modelMngService.pageList(name, pageNum, pageSize));
    }


    @GetMapping("/delete/by/{id}")
    @Operation(summary = "模型管理删除",description = "模型管理删除")
    @Parameter(name = "id",description = "要删除模型的id")
    public R<?> deleteById(@PathVariable String id){
        modelMngService.removeById(id);
        return R.ok();
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "模型管理详情",description = "模型管理详情")
    @Parameter(name = "id",description = "要查看详情的模型id")
    public R<?> detailList(@PathVariable String id){
        return R.ok(modelMngService.list(new LambdaQueryWrapper<ModelMngEntity>()
                .eq(ModelMngEntity::getParentId,id).orderByAsc(ModelMngEntity::getOrderNum)));
    }

//    @ApiOperation("模型管理排序")
    @GetMapping("/change/order")
    @Operation(summary = "模型管理排序",description = "模型管理排序")
    @Parameters({
            @Parameter(name = "id",description = "需要排序的模型id"),
            @Parameter(name = "status",description = "排序：0 升 1 降")
    })
    public R<?> changeOrder(String id, Integer status){
        modelMngService.changeOrder(id,status);
        return R.ok();
    }
}
